home *** CD-ROM | disk | FTP | other *** search
- ;void wrtln(strg,color);
- ; unsigned char *strg,color;
-
- EXTRN _memory_model:byte
- EXTRN _video_buffer:word
- EXTRN _video_page:byte
- EXTRN _snow_protect:byte
-
- _TEXT SEGMENT BYTE PUBLIC 'CODE'
- ASSUME CS:_TEXT
- PUBLIC _wrtln
- _wrtln proc near
- push bp ;
- mov bp,sp ;set stack frame
- push di ;
- push si ;
- cmp _memory_model,0 ;near or far?
- jle begin ;jump if near
- inc bp ;else add 2 to BP
- inc bp ;
- begin: push ds ;DS changed
- cld ;direction flag forward
- mov ax,_video_buffer ;get video buffer address
- mov es,ax ;place in ES
- mov bh,_video_page ;set the cursor page
- mov bl,_snow_protect ;fetch _snow_protect
- mov ah,3 ;BIOS func for cursor pos
- int 10h ;now DH-DL holds row-col
- cmp _memory_model,2 ;data near or far?
- jb L0 ;jump if near
- lds si,dword ptr[bp+4] ;DS:SI pts to Strg
- inc bp ;add 2 to BP since dword ptr
- inc bp ;
- jmp short L00 ;
- L0: mov si,[bp+4] ;near case
- L00: mov [bp+4],bx ;save _video_page and _snow_protect
- sub cx,cx ;clear CX
- push si ;keep initial pointer position
- L000: cmp byte ptr[si],0 ;end of string?
- je L0000 ;jump if so
- inc si ;inc ptr
- inc cx ;inc counter
- jmp short L000 ;loop till end
- L0000: pop si ;restore ptr
- mov ax,160 ;cursor pos: bytes in row
- mul dh ;multiply by num rows
- sub dh,dh ;now DX holds num cols
- shl dx,1 ;double for attri bytes
- add ax,dx ;cursor offset in buffer
- mov di,ax ;now ES:DI pts to pos
- mov bx,3840 ;scrl if won't fit row 24
- sub bx,di ;space left
- mov ax,cx ;chars to be printed
- shl ax,1 ;double for attributes
- or cx,cx ;test for null string
- jnz L1 ;jump if not null
- cmp di,3840 ;last row?
- jnge L1 ;jump if not
- mov al,1 ;scroll if null on Row 25
- jmp short L2 ;jump ahead
- L1: cmp bx,ax ;enough room?
- jge L4 ;jump ahead if so
- sub ax,bx ;amount space required
- mov bl,160 ;bytes in a row
- div bl ;divide
- cmp ah,0 ;any remainder?
- je L2 ;if not, jump ahead
- inc al ;else, scroll 1 more line
- L2: push cx ;save string length
- push bp ;scrolling changes BP
- push ax ;save num lines scrolled
- mov bh,[bp+6] ;attribute of new lines
- mov cx,0000h ;top left row-col
- mov dx,184Fh ;bottom right row-col
- mov ah,6 ;upwards scroll function
- int 10h ;make the scroll
- pop cx ;num lines scrolled in CL
- sub ch,ch ;clear CH, use CX counter
- L3: sub di,160 ;screen ptr back 1 line
- loop L3 ;repeat for ea ln of scrl
- pop bp ;restore BP
- pop cx ;restore string length
- L4: or cx,cx ;test for null string
- jnz L5 ;jump if not null
- add di,160 ;increase screen ptr
- jmp L10 ;jump and set cursor
- L5: mov ah,[bp+6] ;get attribute
- L6: lodsb ;get a character
- mov dx,es ;get video buffer address
- cmp byte ptr[bp+4],0 ;protect against snow?
- je L9 ;jump ahead if not
- mov dx,3dah ;status byte address
- mov bx,ax ;save AX contents
- L7: in al,dx ;get status byte
- test al,1 ;test bit
- jnz L7 ;loop till 0
- cli ;disable interrupts
- L8: in al,dx ;get status byte
- test al,1 ;test bit
- jz L8 ;loop till 1
- mov ax,bx ;char/attri back to AX
- L9: stosw ;write it with attribute
- loop L6 ;go do next char
- L10: sti ;reenable interrupts
- mov ax,di ;now set new cursor pos
- mov dl,160 ;chars in a row
- div dl ;divide scrn ptr
- shr ah,1 ;div remainder by 2
- mov dh,al ;BIOS: row in DH
- mov dl,ah ;col in DL
- cmp dl,0 ;already at new line?
- je L11 ;if so, jump ahead
- inc dh ;else add 1 more line
- mov dl,0 ;set cursor to col 0
- L11: mov bh,[bp+5] ;page number
- mov ah,2 ;function number
- int 10h ;set the cursor
- pop ds ;
- pop si ;
- pop di ;
- pop bp ;
- cmp _memory_model,0 ;quit
- jle quit ;
- db 0CBh ;RET far
- quit: ret ;RET near
- _wrtln endp
- _TEXT ENDS
- END